using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VGBHIST
    {
        public DataRow Convert2GBHIST(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryGBHIST(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["GHMANDANT"] = " ".PadRight(2 ); 
         dwReturn["GHDATE"] = " ".PadRight(8 ); 
         dwReturn["GHPARTIE"] = " ".PadRight(7 ); 
         dwReturn["GHPARTIEKZ"] = " ".PadRight(1 ); 
         dwReturn["GHLO"] = " ".PadRight(2 ); 
         dwReturn["GHLB"] = " ".PadRight(2 ); 
         dwReturn["GHLP"] = " ".PadRight(8 ); 
         dwReturn["GHLBEH"] = " ".PadRight(10 ); 
         dwReturn["GHART"] = " ".PadRight(20 ); 
         dwReturn["GHVAR"] = " ".PadRight(3 ); 
         dwReturn["GHFARBE"] = " ".PadRight(10 ); 
         dwReturn["GHFERTKZ"] = " ".PadRight(1 ); 
         dwReturn["GHZS"] = " ".PadRight(1 ); 
         dwReturn["GHSPSTA"] = " ".PadRight(2 ); 
         dwReturn["GHSPGRD"] = " ".PadRight(2 ); 
         dwReturn["GHBSTKA"] = " ".PadRight(0 ); 
         dwReturn["GHBSTSP"] = " ".PadRight(0 ); 
         dwReturn["GHBSTKG"] = " ".PadRight(0 ); 
         dwReturn["GHBSTKGR"] = " ".PadRight(0 ); 
         dwReturn["GHBSTKGW"] = " ".PadRight(0 ); 
         dwReturn["GHHHK1"] = " ".PadRight(0 ); 
         dwReturn["GHHHK2"] = " ".PadRight(0 ); 
         dwReturn["GHHHK3"] = " ".PadRight(0 ); 
         dwReturn["GHHHK4"] = " ".PadRight(0 ); 
         dwReturn["GHHHK5"] = " ".PadRight(0 ); 
         dwReturn["GHHHK6"] = " ".PadRight(0 ); 
         dwReturn["GHHHK7"] = " ".PadRight(0 ); 
         dwReturn["GHHHK8"] = " ".PadRight(0 ); 
         dwReturn["GHHHK9"] = " ".PadRight(0 ); 
         dwReturn["GHHHK10"] = " ".PadRight(0 ); 
         dwReturn["GHHHKG"] = " ".PadRight(0 ); 
         dwReturn["GHAHK1"] = " ".PadRight(0 ); 
         dwReturn["GHAHK2"] = " ".PadRight(0 ); 
         dwReturn["GHAHK3"] = " ".PadRight(0 ); 
         dwReturn["GHAHK4"] = " ".PadRight(0 ); 
         dwReturn["GHAHK5"] = " ".PadRight(0 ); 
         dwReturn["GHAHK6"] = " ".PadRight(0 ); 
         dwReturn["GHAHK7"] = " ".PadRight(0 ); 
         dwReturn["GHAHK8"] = " ".PadRight(0 ); 
         dwReturn["GHAHK9"] = " ".PadRight(0 ); 
         dwReturn["GHAHK10"] = " ".PadRight(0 ); 
         dwReturn["GHAHKG"] = " ".PadRight(0 ); 
         dwReturn["GHABPZAB"] = " ".PadRight(0 ); 
         dwReturn["GHBPREIS"] = " ".PadRight(0 ); 
         dwReturn["GHPART"] = " ".PadRight(5 ); 
         dwReturn["GHAVPREIS"] = " ".PadRight(0 ); 
         dwReturn["GHIPREIS"] = " ".PadRight(0 ); 
         dwReturn["GHINDAT"] = " ".PadRight(0 ); 
         dwReturn["GHFILLER"] = " ".PadRight(20 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapGBHIST(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveGBHIST(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryGBHIST(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapGBHIST(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertGBHIST(dwLocal, ITXDBVERSION);
            }
            UpdateGBHIST(dwLocal);
        }
        public void InsertGBHIST(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO GBHIST(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryGBHIST(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM GBHIST WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM GBHIST  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "GBHIST";
            Return = Result;
            return Return;
        }
        public void DeleteGBHIST(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM GBHIST   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateGBHIST(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE GBHIST SET "
                    +"GHMANDANT= :GHMANDANT,"
                    +"GHDATE= :GHDATE,"
                    +"GHPARTIE= :GHPARTIE,"
                    +"GHPARTIEKZ= :GHPARTIEKZ,"
                    +"GHLO= :GHLO,"
                    +"GHLB= :GHLB,"
                    +"GHLP= :GHLP,"
                    +"GHLBEH= :GHLBEH,"
                    +"GHART= :GHART,"
                    +"GHVAR= :GHVAR,"
                    +"GHFARBE= :GHFARBE,"
                    +"GHFERTKZ= :GHFERTKZ,"
                    +"GHZS= :GHZS,"
                    +"GHSPSTA= :GHSPSTA,"
                    +"GHSPGRD= :GHSPGRD,"
                    +"GHBSTKA= :GHBSTKA,"
                    +"GHBSTSP= :GHBSTSP,"
                    +"GHBSTKG= :GHBSTKG,"
                    +"GHBSTKGR= :GHBSTKGR,"
                    +"GHBSTKGW= :GHBSTKGW,"
                    +"GHHHK1= :GHHHK1,"
                    +"GHHHK2= :GHHHK2,"
                    +"GHHHK3= :GHHHK3,"
                    +"GHHHK4= :GHHHK4,"
                    +"GHHHK5= :GHHHK5,"
                    +"GHHHK6= :GHHHK6,"
                    +"GHHHK7= :GHHHK7,"
                    +"GHHHK8= :GHHHK8,"
                    +"GHHHK9= :GHHHK9,"
                    +"GHHHK10= :GHHHK10,"
                    +"GHHHKG= :GHHHKG,"
                    +"GHAHK1= :GHAHK1,"
                    +"GHAHK2= :GHAHK2,"
                    +"GHAHK3= :GHAHK3,"
                    +"GHAHK4= :GHAHK4,"
                    +"GHAHK5= :GHAHK5,"
                    +"GHAHK6= :GHAHK6,"
                    +"GHAHK7= :GHAHK7,"
                    +"GHAHK8= :GHAHK8,"
                    +"GHAHK9= :GHAHK9,"
                    +"GHAHK10= :GHAHK10,"
                    +"GHAHKG= :GHAHKG,"
                    +"GHABPZAB= :GHABPZAB,"
                    +"GHBPREIS= :GHBPREIS,"
                    +"GHPART= :GHPART,"
                    +"GHAVPREIS= :GHAVPREIS,"
                    +"GHIPREIS= :GHIPREIS,"
                    +"GHINDAT= :GHINDAT,"
                    +"GHFILLER= :GHFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("GHMANDANT", OracleType.NVarChar).Value = dwData["GHMANDANT"].ToString(); 
          or1.Parameters.Add("GHDATE", OracleType.NVarChar).Value = dwData["GHDATE"].ToString(); 
          or1.Parameters.Add("GHPARTIE", OracleType.NVarChar).Value = dwData["GHPARTIE"].ToString(); 
          or1.Parameters.Add("GHPARTIEKZ", OracleType.NVarChar).Value = dwData["GHPARTIEKZ"].ToString(); 
          or1.Parameters.Add("GHLO", OracleType.NVarChar).Value = dwData["GHLO"].ToString(); 
          or1.Parameters.Add("GHLB", OracleType.NVarChar).Value = dwData["GHLB"].ToString(); 
          or1.Parameters.Add("GHLP", OracleType.NVarChar).Value = dwData["GHLP"].ToString(); 
          or1.Parameters.Add("GHLBEH", OracleType.NVarChar).Value = dwData["GHLBEH"].ToString(); 
          or1.Parameters.Add("GHART", OracleType.NVarChar).Value = dwData["GHART"].ToString(); 
          or1.Parameters.Add("GHVAR", OracleType.NVarChar).Value = dwData["GHVAR"].ToString(); 
          or1.Parameters.Add("GHFARBE", OracleType.NVarChar).Value = dwData["GHFARBE"].ToString(); 
          or1.Parameters.Add("GHFERTKZ", OracleType.NVarChar).Value = dwData["GHFERTKZ"].ToString(); 
          or1.Parameters.Add("GHZS", OracleType.NVarChar).Value = dwData["GHZS"].ToString(); 
          or1.Parameters.Add("GHSPSTA", OracleType.NVarChar).Value = dwData["GHSPSTA"].ToString(); 
          or1.Parameters.Add("GHSPGRD", OracleType.NVarChar).Value = dwData["GHSPGRD"].ToString(); 
          or1.Parameters.Add("GHBSTKA", OracleType.NVarChar).Value = dwData["GHBSTKA"].ToString(); 
          or1.Parameters.Add("GHBSTSP", OracleType.NVarChar).Value = dwData["GHBSTSP"].ToString(); 
          or1.Parameters.Add("GHBSTKG", OracleType.NVarChar).Value = dwData["GHBSTKG"].ToString(); 
          or1.Parameters.Add("GHBSTKGR", OracleType.NVarChar).Value = dwData["GHBSTKGR"].ToString(); 
          or1.Parameters.Add("GHBSTKGW", OracleType.NVarChar).Value = dwData["GHBSTKGW"].ToString(); 
          or1.Parameters.Add("GHHHK1", OracleType.NVarChar).Value = dwData["GHHHK1"].ToString(); 
          or1.Parameters.Add("GHHHK2", OracleType.NVarChar).Value = dwData["GHHHK2"].ToString(); 
          or1.Parameters.Add("GHHHK3", OracleType.NVarChar).Value = dwData["GHHHK3"].ToString(); 
          or1.Parameters.Add("GHHHK4", OracleType.NVarChar).Value = dwData["GHHHK4"].ToString(); 
          or1.Parameters.Add("GHHHK5", OracleType.NVarChar).Value = dwData["GHHHK5"].ToString(); 
          or1.Parameters.Add("GHHHK6", OracleType.NVarChar).Value = dwData["GHHHK6"].ToString(); 
          or1.Parameters.Add("GHHHK7", OracleType.NVarChar).Value = dwData["GHHHK7"].ToString(); 
          or1.Parameters.Add("GHHHK8", OracleType.NVarChar).Value = dwData["GHHHK8"].ToString(); 
          or1.Parameters.Add("GHHHK9", OracleType.NVarChar).Value = dwData["GHHHK9"].ToString(); 
          or1.Parameters.Add("GHHHK10", OracleType.NVarChar).Value = dwData["GHHHK10"].ToString(); 
          or1.Parameters.Add("GHHHKG", OracleType.NVarChar).Value = dwData["GHHHKG"].ToString(); 
          or1.Parameters.Add("GHAHK1", OracleType.NVarChar).Value = dwData["GHAHK1"].ToString(); 
          or1.Parameters.Add("GHAHK2", OracleType.NVarChar).Value = dwData["GHAHK2"].ToString(); 
          or1.Parameters.Add("GHAHK3", OracleType.NVarChar).Value = dwData["GHAHK3"].ToString(); 
          or1.Parameters.Add("GHAHK4", OracleType.NVarChar).Value = dwData["GHAHK4"].ToString(); 
          or1.Parameters.Add("GHAHK5", OracleType.NVarChar).Value = dwData["GHAHK5"].ToString(); 
          or1.Parameters.Add("GHAHK6", OracleType.NVarChar).Value = dwData["GHAHK6"].ToString(); 
          or1.Parameters.Add("GHAHK7", OracleType.NVarChar).Value = dwData["GHAHK7"].ToString(); 
          or1.Parameters.Add("GHAHK8", OracleType.NVarChar).Value = dwData["GHAHK8"].ToString(); 
          or1.Parameters.Add("GHAHK9", OracleType.NVarChar).Value = dwData["GHAHK9"].ToString(); 
          or1.Parameters.Add("GHAHK10", OracleType.NVarChar).Value = dwData["GHAHK10"].ToString(); 
          or1.Parameters.Add("GHAHKG", OracleType.NVarChar).Value = dwData["GHAHKG"].ToString(); 
          or1.Parameters.Add("GHABPZAB", OracleType.NVarChar).Value = dwData["GHABPZAB"].ToString(); 
          or1.Parameters.Add("GHBPREIS", OracleType.NVarChar).Value = dwData["GHBPREIS"].ToString(); 
          or1.Parameters.Add("GHPART", OracleType.NVarChar).Value = dwData["GHPART"].ToString(); 
          or1.Parameters.Add("GHAVPREIS", OracleType.NVarChar).Value = dwData["GHAVPREIS"].ToString(); 
          or1.Parameters.Add("GHIPREIS", OracleType.NVarChar).Value = dwData["GHIPREIS"].ToString(); 
          or1.Parameters.Add("GHINDAT", OracleType.NVarChar).Value = dwData["GHINDAT"].ToString(); 
          or1.Parameters.Add("GHFILLER", OracleType.NVarChar).Value = dwData["GHFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
